<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <!--Setting-->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <meta http-equiv="Cache-Control" content="no-transform">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta name="apple-mobile-web-app-capable" content="efinedxq">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,adress=no">
    <meta name="browsermode" content="application">
    <meta name="screen-orientation" content="portrait">
    <link rel="dns-prefetch" href="https://efinedxq.github.io">
    <!--SEO-->





<meta name="robots" content="all" />
<meta name="google" content="all" />
<meta name="googlebot" content="all" />
<meta name="verify" content="all" />
    <!--Title-->


<title>牛客-北邮-C反转 | efinedxq</title>


    <link rel="alternate" href="/atom.xml" title="efinedxq" type="application/atom+xml">


    <link rel="icon" href="/favicon.ico">

    



<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css?rev=3.3.4">
<link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/style.css?rev=@@hash">




    
    <div class="hide">
    	<script src="https://s4.cnzz.com/z_stat.php?id=1263868967&web_id=1263868967" language="JavaScript"></script>
    </div>






    
</head>


<!--[if lte IE 8]>
<style>
    html{ font-size: 1em }
</style>
<![endif]-->
<!--[if lte IE 9]>
<div style="ie">你使用的浏览器版本过低，为了你更好的阅读体验，请更新浏览器的版本或者使用其他现代浏览器，比如Chrome、Firefox、Safari等。</div>
<![endif]-->

<body>
    <header class="main-header"  style="background-image:url(/img/banner2.jpg)"  >
    <div class="main-header-box">
        <a class="header-avatar" href="/" title="">
            <img src="/img/author.jpg" alt="logo头像">
        </a>
        <div class="branding">
        	<!--<h2 class="text-hide">Snippet主题,从未如此简单有趣</h2>-->
            
                <h1> 往者不可谏,来者犹可追。 </h1>
             
    	</div>
    </div>
</header>
    <nav class="main-navigation">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <div class="navbar-header"><span class="nav-toggle-button collapsed" data-toggle="collapse" data-target="#main-menu" id="mnav">
                    <span class="sr-only">Toggle navigation</span>
                    <i class="fa fa-bars"></i>
                    </span>
                </div>
                <div class="collapse navbar-collapse" id="main-menu">
                    <ul class="menu">
                        
                            <li role="presentation"><a href="/"><i class="fa fa-fw "></i>首页</a>
                            </li>
                        
                            <li role="presentation"><a href="/categories/"><i class="fa fa-fw "></i>前端</a>
                            </li>
                        
                            <li role="presentation"><a href="/categories/"><i class="fa fa-fw "></i>后端</a>
                            </li>
                        
                            <li role="presentation"><a href="/categories/"><i class="fa fa-fw "></i>工具</a>
                            </li>
                        
                            <li role="presentation"><a href="/categories/题解/"><i class="fa fa-fw "></i>题解</a>
                            </li>
                        
                            <li role="presentation"><a href="/categories/"><i class="fa fa-fw "></i>资源</a>
                            </li>
                        
                    </ul>
                </div>
            </div>
        </div>
    </div>
</nav>
    <section class="content-wrap">
        <div class="container">
            <div class="row">
                <main class="col-md-8 main-content m-post">
                    <p id="process"></p>
<article class="post">
    <div class="post-head">
        <h1 id="牛客-北邮-C反转">
            
	            牛客-北邮-C反转
            
        </h1>
        <div class="post-meta">
    
    
    <span class="categories-meta fa-wrap">
        <i class="fa fa-folder-open-o"></i>
        <span>北邮</span>
    </span>
    
    
    <span class="fa-wrap">
        <i class="fa fa-tags"></i>
        <span class="tags-meta">
            
            数组
            
        </span>
    </span>
    
    
    <span class="fa-wrap">
        <i class="fa fa-clock-o"></i>
        <span class="date-meta">2018/01/26</span>
    </span>
</div>

            
            
    </div>
    
    <div class="post-body post-content">
        <h3 id="题目描述"><a href="#题目描述" class="headerlink" title="题目描述"></a>题目描述</h3><p>首先输入一个5 * 5的数组，然后输入一行，这一行有四个数，前两个代表操作类型，后两个数x y代表需操作数据为以x y为左上角的那几个数据。 操作类型有四种：  1 2 表示：90度，顺时针，翻转4个数  1 3 表示：90度，顺时针，翻转9个数  2 2 表示：90度，逆时针，翻转4个数  2 3 表示：90度，逆时针，翻转9个数 </p>
<hr>
<h3 id="输入描述"><a href="#输入描述" class="headerlink" title="输入描述:"></a>输入描述:</h3><p>输入有多组数据。<br>每组输入一个5 * 5的数组，然后输入一行，这一行有四个数，前两个代表操作类型，后两个数x y代表需操作数据为以x y为左上角的那几个数据。</p>
<hr>
<h3 id="输出描述"><a href="#输出描述" class="headerlink" title="输出描述:"></a>输出描述:</h3><p>输出翻转后的数组。</p>
<hr>
<h3 id="示例1"><a href="#示例1" class="headerlink" title="示例1"></a>示例1</h3><p>输入</p>
<blockquote>
<p>1 2 3 4 5<br>6 7 8 9 10<br>11 12 13 14 15<br>16 17 18 19 20<br>21 22 23 24 25<br>1 3 1 1</p>
</blockquote>
<p>输出</p>
<blockquote>
<p>11 6 1 4 5<br>12 7 2 9 10<br>13 8 3 14 15<br>16 17 18 19 20<br>21 22 23 24 25</p>
</blockquote>
<hr>
<h3 id="分析"><a href="#分析" class="headerlink" title="分析"></a>分析</h3><p>用的方法比较笨，比较暴力，挨个交换。</p>
<hr>
<h3 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h3><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;vector&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;queue&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> num[<span class="number">6</span>][<span class="number">6</span>], n, m, x, y;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;=<span class="number">5</span>; i ++ )</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> j = <span class="number">1</span>; j &lt;= <span class="number">5</span>; j ++) </span><br><span class="line">			<span class="built_in">cin</span>&gt;&gt;num[i][j];</span><br><span class="line">	<span class="built_in">cin</span>&gt;&gt;n&gt;&gt;m&gt;&gt;x&gt;&gt;y;</span><br><span class="line">  </span><br><span class="line">	<span class="keyword">if</span>(n==<span class="number">1</span>&amp;&amp;m==<span class="number">2</span>)&#123;</span><br><span class="line">		<span class="keyword">int</span> tem = num[x][y];</span><br><span class="line">		num[x][y] = num[x+<span class="number">1</span>][y];</span><br><span class="line">		num[x+<span class="number">1</span>][y] = num[x+<span class="number">1</span>][y+<span class="number">1</span>];</span><br><span class="line">		num[x+<span class="number">1</span>][y+<span class="number">1</span>] = num[x][y+<span class="number">1</span>];</span><br><span class="line">		num[x][y+<span class="number">1</span>] = tem;</span><br><span class="line">	&#125;<span class="keyword">else</span> <span class="keyword">if</span>(n==<span class="number">1</span>&amp;&amp;m==<span class="number">3</span>)&#123;</span><br><span class="line">		<span class="keyword">int</span> tem = num[x][y];</span><br><span class="line">		num[x][y] = num[x+<span class="number">2</span>][y];</span><br><span class="line">		num[x+<span class="number">2</span>][y] = num[x+<span class="number">2</span>][y+<span class="number">2</span>];</span><br><span class="line">		num[x+<span class="number">2</span>][y+<span class="number">2</span>] = num[x][y+<span class="number">2</span>];</span><br><span class="line">		num[x][y+<span class="number">2</span>] = tem;</span><br><span class="line">		</span><br><span class="line">		tem = num[x][y+<span class="number">1</span>];</span><br><span class="line">		num[x][y+<span class="number">1</span>] = num[x+<span class="number">1</span>][y];</span><br><span class="line">		num[x+<span class="number">1</span>][y] = num[x+<span class="number">2</span>][y+<span class="number">1</span>];</span><br><span class="line">		num[x+<span class="number">2</span>][y+<span class="number">1</span>] = num[x+<span class="number">1</span>][y+<span class="number">2</span>];</span><br><span class="line">		num[x+<span class="number">1</span>][y+<span class="number">2</span>] = tem;</span><br><span class="line">	&#125;<span class="keyword">else</span> <span class="keyword">if</span>(n==<span class="number">2</span>&amp;&amp;m==<span class="number">2</span>)&#123;</span><br><span class="line">		<span class="keyword">int</span> tem = num[x][y];</span><br><span class="line">		num[x][y] = num[x][y+<span class="number">1</span>];</span><br><span class="line">		num[x][y+<span class="number">1</span>] = num[x+<span class="number">1</span>][y+<span class="number">1</span>];</span><br><span class="line">		num[x+<span class="number">1</span>][y+<span class="number">1</span>] = num[x+<span class="number">1</span>][y];</span><br><span class="line">		num[x+<span class="number">1</span>][y] = tem;</span><br><span class="line">	&#125;<span class="keyword">else</span> <span class="keyword">if</span>(n==<span class="number">2</span>&amp;&amp;m==<span class="number">3</span>)&#123;</span><br><span class="line">		<span class="keyword">int</span> tem = num[x][y];</span><br><span class="line">		num[x][y] = num[x][y+<span class="number">2</span>];</span><br><span class="line">		num[x][y+<span class="number">2</span>] = num[x+<span class="number">2</span>][y+<span class="number">2</span>];</span><br><span class="line">		num[x+<span class="number">2</span>][y+<span class="number">2</span>] = num[x+<span class="number">2</span>][y];</span><br><span class="line">		num[x+<span class="number">2</span>][y] = tem;</span><br><span class="line">		</span><br><span class="line">		tem = num[x][y+<span class="number">1</span>];</span><br><span class="line">		num[x][y+<span class="number">1</span>] = num[x+<span class="number">1</span>][y+<span class="number">2</span>];</span><br><span class="line">		num[x+<span class="number">1</span>][y+<span class="number">2</span>] = num[x+<span class="number">2</span>][y+<span class="number">1</span>];</span><br><span class="line">		num[x+<span class="number">2</span>][y+<span class="number">1</span>] = num[x+<span class="number">1</span>][y];</span><br><span class="line">		num[x+<span class="number">1</span>][y] = tem;</span><br><span class="line">	&#125;</span><br><span class="line">	 </span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= <span class="number">5</span>;i ++)&#123;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> j = <span class="number">1</span>; j &lt;= <span class="number">5</span>; j ++)&#123;</span><br><span class="line">		   <span class="built_in">cout</span>&lt;&lt;num[i][j];</span><br><span class="line">		   <span class="keyword">if</span>(j==<span class="number">5</span>) <span class="built_in">cout</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">		   <span class="keyword">else</span> <span class="built_in">cout</span>&lt;&lt;<span class="string">" "</span>;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

    </div>

    <div class="post-footer">   
        <div>
            
                转载声明：商业转载请联系作者获得授权,非商业转载请注明出处 © <a href="" target="_blank">efinedxq</a>
            
        </div>
        <div>
            
        </div>  
    </div>
</article>

<div class="article-nav prev-next-wrap clearfix">
    
        <a href="/题解/牛客/北邮/牛客-北邮-打牌/" class="pre-post btn btn-default"><i class="fa fa-angle-left fa-fw"></i>上一篇</a>
    
    
        <a href="/题解/牛客/北邮/牛客-北邮-矩阵幂/" class="next-post btn btn-default">下一篇<i class="fa fa-angle-right fa-fw"></i></a>
    
</div>


    <div id="comments">
        
	
<div id="lv-container" data-id="city" data-uid="MTAyMC8zMzA1MS85NjEz">
  <script type="text/javascript">
     (function(d, s) {
         var j, e = d.getElementsByTagName(s)[0];
         if (typeof LivereTower === 'function') { return; }
         j = d.createElement(s);
         j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
         j.async = true;
         e.parentNode.insertBefore(j, e);
     })(document, 'script');
  </script>
</div>


    </div>





                </main>
                
    <aside class="col-md-4 sidebar">
        
        
    <div class="widget">    
        <h3 class="title">搜索</h3>
        <div id="search-form">
            <div id="result-mask" class="hide"></div>
            <div class="search-area">
                
                    <input id="search-key" type="search" autocomplete="off" placeholder="搜点什么呢?">
                    <button type="button" class="search-form-submit" id="search-local">站内搜索</button>
                
                
            </div>
            <div id="result-wrap" class="hide">
                <div id="search-result"></div>
            </div>
            <div class="hide">
                <template id="search-tpl">
                    <div class="item">
                        <a href="/{path}" title="{title}">
                            <div class="title">{title}</div>
                            <div class="content">{content}</div>
                        </a>
                    </div>
                </template>
            </div>
        </div>
    </div>

        
        
  <div class="widget">
    <h3 class="title">标签云</h3>
    <div class="content tag-cloud">
        <a href="/tags/leetcode/" style="font-size: 16.67px;">leetcode</a> <a href="/tags/map/" style="font-size: 10px;">map</a> <a href="/tags/中间数/" style="font-size: 10px;">中间数</a> <a href="/tags/二叉排序树/" style="font-size: 10px;">二叉排序树</a> <a href="/tags/二叉树/" style="font-size: 10px;">二叉树</a> <a href="/tags/二进制/" style="font-size: 10px;">二进制</a> <a href="/tags/优先队列/" style="font-size: 13.33px;">优先队列</a> <a href="/tags/动态规划/" style="font-size: 10px;">动态规划</a> <a href="/tags/博客配置/" style="font-size: 10px;">博客配置</a> <a href="/tags/反序/" style="font-size: 10px;">反序</a> <a href="/tags/哈夫曼树/" style="font-size: 10px;">哈夫曼树</a> <a href="/tags/复数/" style="font-size: 10px;">复数</a> <a href="/tags/字符串/" style="font-size: 16.67px;">字符串</a> <a href="/tags/指针/" style="font-size: 10px;">指针</a> <a href="/tags/排序/" style="font-size: 13.33px;">排序</a> <a href="/tags/数学/" style="font-size: 20px;">数学</a> <a href="/tags/数组/" style="font-size: 20px;">数组</a> <a href="/tags/暴力/" style="font-size: 10px;">暴力</a> <a href="/tags/最长子串/" style="font-size: 10px;">最长子串</a> <a href="/tags/枚举/" style="font-size: 13.33px;">枚举</a> <a href="/tags/查找/" style="font-size: 13.33px;">查找</a> <a href="/tags/栈/" style="font-size: 10px;">栈</a> <a href="/tags/树遍历/" style="font-size: 10px;">树遍历</a> <a href="/tags/比较查找/" style="font-size: 10px;">比较查找</a> <a href="/tags/矩阵/" style="font-size: 10px;">矩阵</a> <a href="/tags/类排序/" style="font-size: 10px;">类排序</a> <a href="/tags/约数/" style="font-size: 10px;">约数</a> <a href="/tags/结构体/" style="font-size: 13.33px;">结构体</a> <a href="/tags/质因数/" style="font-size: 10px;">质因数</a> <a href="/tags/递归/" style="font-size: 10px;">递归</a> <a href="/tags/链表/" style="font-size: 10px;">链表</a>
    </div>
  </div>


        
        
    <div class="widget">
        <h3 class="title">分类</h3>
        <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/hexo/"><i class="fa" aria-hidden="true">hexo</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/题解/"><i class="fa" aria-hidden="true">题解</i></a><span class="category-list-count">24</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/题解/LeetCode/"><i class="fa" aria-hidden="true">LeetCode</i></a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/题解/牛客/"><i class="fa" aria-hidden="true">牛客</i></a><span class="category-list-count">20</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/题解/牛客/北邮/"><i class="fa" aria-hidden="true">北邮</i></a><span class="category-list-count">13</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/题解/牛客/清华/"><i class="fa" aria-hidden="true">清华</i></a><span class="category-list-count">7</span></li></ul></li></ul></li></ul>
    </div>


        
        
    <div class="widget">
      <h3 class="title">归档</h3>
        <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/02/"><i class="fa" aria-hidden="true">二月 2018</i></a><span class="archive-list-count">8</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/01/"><i class="fa" aria-hidden="true">一月 2018</i></a><span class="archive-list-count">20</span></li></ul>
    </div>


        
        
    <div class="widget">
        <h3 class="title">友链</h3>
        <div class="content friends-link">
        
            <a href="http://blog.csdn.net/efine_dxq" class="fa" target="_blank">个人博客</a>
        
        </div>
    </div>


        
        
    <div class="widget">
      <h3 class="title">社交</h3> 
        <div class="content social">
            
	            <a href="//github.com/efinedxq" rel="external nofollow" title="Github" target="_blank">
			    	<i class="git fa fa-git"></i>
			    </a>
            
	            <a href="mailto:dangxq1008@163.com" rel="external nofollow" title="邮箱" target="_blank">
			    	<i class="envelope-o fa fa-envelope-o"></i>
			    </a>
            
	            <a href="/" rel="external nofollow" title="联系QQ" target="_blank">
			    	<i class="qq fa fa-qq"></i>
			    </a>
            
	            <a href="/" rel="external nofollow" title="微博" target="_blank">
			    	<i class="weibo fa fa-weibo"></i>
			    </a>
            
	            <a href="/" rel="external nofollow" title="QQ群" target="_blank">
			    	<i class="users fa fa-users"></i>
			    </a>
            
	            <a href="/atom.xml" rel="external nofollow" title="RSS" target="_blank">
			    	<i class="feed fa fa-feed"></i>
			    </a>
            
        </div>
    </div>


        
        
    <div class="widget notification">
        <h3 class="title">网站公告</h3>
        <div>
            <p>主题Snippet v1.2.0版本已经上线！欢迎更新~ <br/>
主题下载：<a href="https://github.com/shenliyang/hexo-theme-snippet" title="fork me" target="_blank">Snippet主题</a> <br/>
<hr/>接受贡献，包括不限于提交问题与需求，修复代码。欢迎Pull Request<br/>支持主题：<a href="https://github.com/shenliyang/hexo-theme-snippet/stargazers">Star一下</a>
</p>
        </div>
    </div>

        
    </aside>

            </div>
        </div>
    </section>
    <footer class="main-footer">
    <div class="container">
        <div class="row">
        </div>
    </div>
</footer>

<a id="back-to-top" class="hide">
	<i class="fa fa-chevron-up"></i>
</a>




    <div class="copyright">
    <div class="container">
        <div class="row">
            <div class="col-sm-12"> 
                <span>Copyright &copy; 2017
                </span> | 
                <span>
                    Powered by <a href="//hexo.io" class="copyright-links" target="_blank" rel="nofollow">Hexo</a>
                </span> | 
                <span>
                    Theme by <a href="//github.com/shenliyang/hexo-theme-snippet.git" class="copyright-links" target="_blank" rel="nofollow">Snippet</a>
                </span>
            </div>
        </div>
    </div>
</div>



	<script src="/js/search.js?rev=@@hash"></script>


<script src="/js/app.js?rev=@@hash"></script>


</body>
</html>